package club.pchome.controller;

import club.pchome.dto.Result;
import club.pchome.ex.ServiceException;
import club.pchome.ex.code.BaseResponseCode;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "游戏功能类")

@RestController
public class GameController extends BaseController{


    /**
     * 1 - 石头; 2 - 剪刀; 3-布 游戏
     * 1>2 , 2>3, 3>1
     * @param type
     * @return
     */
    @PostMapping("/fingerGuessing")
    public Result<String> fingerGuessing(int type) throws ServiceException {
        String[] rule = {"石头" , "剪刀" , "布"};
        if( type > rule.length || type < 1){
            throw new ServiceException(BaseResponseCode.SYSTEM_PARAM_ERROR);
        }

        //系统出手
        int sys = (int)(Math.random()*10)%3+1;

        logger.info("你出的是（"+rule[type-1]+"） 电脑出的是（"+rule[sys-1]+"）");

        //根据出拳判断输赢
        if((type==1&&sys==2) || (type==2&&sys==3) || (type==3&&sys==1)){
            return Result.initSuccessResult("【恭喜你赢了！！！】, 送你一份小礼物");
        }else if (type == sys){
            return Result.initSuccessResult("【平局！再来一次吧】");
        }else{
            return Result.initSuccessResult("【你输了！再来一次吧】");
        }
    }

}
